package com.ibeeking.found.msg.api.feign.fallback;

import com.ibeeking.found.msg.api.feign.MsgMemberCClient;
import com.ibeeking.nematos.utils.result.ResponseCodeEnum;
import com.ibeeking.nematos.utils.result.ResponseResult;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.List;

/**
 * 降级工场
 *
 * @Author ibeeking
 * @date 2019/1/18
 */
@Component
public class MsgMemberCFallbackFactory implements FallbackFactory<MsgMemberCClient> {
    @Override
    public MsgMemberCClient create(Throwable throwable) {
        return new MsgMemberCClient() {
            @Override
            public ResponseResult<List<String>> queryUnionIds(List<Long> memberIds) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "查询会员UnionIds失败。" + throwable.getMessage(), Collections.emptyList());
            }

            @Override
            public ResponseResult<List<String>> queryMobiles(List<Long> memberIds) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "根据会员ids查询会员手机号失败。" + throwable.getMessage(), Collections.emptyList());
            }
        };
    }
}
